<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Roster extends CI_Controller {

	function __construct()
	{
		parent::__construct();
	}

    function index()
    {
        $data['title'] = "New Jersey Devils - Roster";
        $data['body'] = 'v_roster';
        $data['players'] = "undefined";
        //$this->load->vars($data);
        $this->load->view('template', $data);
    }

    function process()
    {
        $orderBy = $this->input->post('orderBy');
        $roster = simplexml_load_file("./data/roster.xml");
        $players = array();
        $totalPlayers = array();

        foreach ($roster->player as $player)
        {
            $totalPlayers = $player;
        }

        if ($orderBy == null)
        {
            foreach ($roster->player as $player)
                {
                    $players[] = $player;
                }
        }
        else if ($orderBy == "num")
        {
            $count = 1;
            while($count < 99)
            {
                foreach ($roster->player as $player)
                {
                    if($count == $player['num'])
                    {
                        $players[] = $player;
                    }
                }
                $count++;
            }
        }
        else if ($orderBy == "pos")
        {
            foreach ($roster->player as $player)
            {
                $players[] = $player;
            }
        }
        else if ($orderBy == "fname")
        {
            foreach ($roster->player as $player)
            {
                $players[] = $player;
            }
        }
        else if ($orderBy == "lname")
        {
            foreach ($roster->player as $player)
            {
                $players[] = $player;
            }
        }

        $data['title'] = "Roster";
        $data['body'] = "v_roster";
        $data['players'] = $players;
        $this->load->vars($data);
        $this->load->view('template');
    }

}

/* End of file roster.php */
/* Location: ./application/controllers/roster.php */